﻿// =================================================================== 
// 项目说明
//====================================================================
// lsc。@Copy Right 2019
// 文件： Guidance.cs
// 项目名称：斑马车务
// 创建时间：2019-01-09
// 负责人：lsc
// ===================================================================
using System;
using System.Data;
using System.Collections.Generic;
using Dapper.Extensions;
using CGT.Infrastructure.Entity;
using CGT.Infrastructure.Repository;
namespace CGT.Infrastructure.Service
{
	
	/// <summary>
	///办事指南
	/// </summary>
	public class GuidanceService
	{
         protected GuidanceRepository repository;
         
         public  GuidanceService(){
           repository = new GuidanceRepository();         
         }
         
        #region 增删改查

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public object Insert(Guidance entity) { return repository.Insert(entity); }

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public object Insert(List<Guidance> entitys) { return repository.Insert(entitys); }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public bool Update(Guidance entity) { return repository.Update(entity); }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public bool Delete(Guidance entity) { return repository.Delete(entity); }

        /// <summary>
        /// 删除所有
        /// </summary>
        /// <returns></returns>
        public bool DeleteAll() { return repository.DeleteAll(); }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public bool Delete(int primaryKey) { return repository.Delete(primaryKey); }

        /// <summary>
        /// 查询单个实体
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public Guidance SingleOrDefault(object primaryKey) { return repository.SingleOrDefault(primaryKey); }

        /// <summary>
        /// 查询单个实体,如果存在多条则引发异常
        /// </summary>
        /// <param name="sql">查询语句</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        public Guidance SingleOrDefault(string sql, object param = null) { return repository.SingleOrDefault(sql, param); }

        /// <summary>
        /// 查询单个实体
        /// </summary>
        /// <param name="sql">查询语句</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        public Guidance FirstOrDefault(string sql, object param = null) { return repository.FirstOrDefault(sql, param); }

        /// <summary>
        /// 查询单个实体,如果存在多条则引发异常
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public Guidance Single(object primaryKey) { return repository.Single(primaryKey); }

        /// <summary>
        /// 查询单个实体,如果存在多条则引发异常
        /// </summary>
        /// <param name="sql">查询语句</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        public Guidance Single(string sql, object param = null) { return repository.Single(sql, param); }

        /// <summary>
        /// 查询单个实体
        /// </summary>
        /// <param name="sql">查询语句</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        public Guidance First(string sql, object param = null) { return repository.First(sql, param); }

        /// <summary>
        /// 查询所有
        /// </summary>
        /// <returns></returns>
        public List<Guidance> QueryAll()
        {
            return repository.QueryAll();
        }

        /// <summary>
        /// 批量查询
        /// </summary>
        /// <param name="sql">查询语句</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        public List<Guidance> Query(string sql, object param = null) { return repository.Query(sql, param); }

        /// <summary>
        /// 批量查询
        /// </summary>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">每页记录</param>
        /// <param name="sql">查询语句</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        public List<Guidance> QueryList(long pageIndex, long pageSize, string sql, params object[] param) { return repository.QueryList(pageIndex, pageSize, sql, param); }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">每页大小</param>
        /// <param name="sql">查询语句</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        public Page<Guidance> Pages(long pageIndex, long pageSize, string sql, params object[] param) { return repository.Pages(pageIndex, pageSize, sql, param); }

        /// <summary>
        /// 返回受影响的行数
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public int Execute(string sql, object param = null) { return repository.Execute(sql, param); }

        /// <summary>
        /// 执行查询，并返回查询所返回的结果集中第一行的第一列。 忽略额外的列或行。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public T ExecuteScalar<T>(string sql, object param = null) { return repository.ExecuteScalar<T>(sql, param); }

        /// <summary>
        /// 执行查询 
		/// 尽量用实体查询
        /// </summary>
        /// <param name="sql">查询语句</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        public DataTable QueryTable(string sql, object param = null)
        {
            return repository.QueryTable(sql, param);
        }

        /// <summary>
        /// 批量插入
        /// 每次插入的数量最好进行测试,否则会影响性能
        /// </summary>
        /// <param name="pocos"></param>
        /// <returns></returns>
        public int BatchInsert(string sql, List<Guidance> pocos)
        {
            return repository.BatchInsert(sql, pocos);
        }
        #endregion
	}
	
}